package us.wili.dev.netty.model;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

public class RequestDto {
    /**
     * 请求编码
     */
    private Integer cmd;
    /**
     * 请求标识
     */
    private String requestId;
    /**
     * 参数
     */
    private Object param;


    public <T> T getParam(Class<T> clazz){
        if (param == null){
            return null;
        }else{
            String paramStr = JSON.toJSONString(param);
            return JSON.parseObject(paramStr,clazz);
        }
    }

    public String getStringParamByKey(String key){
        if (param == null){
            return null;
        }else{
            JSONObject jsonObject = (JSONObject) JSON.toJSON(param);
            return jsonObject.getString(key);
        }
    }

    public Long getLongParamByKey(String key){
        if (param == null){
            return null;
        }else {
            JSONObject jsonObject = (JSONObject) JSON.toJSON(param);
            return jsonObject.getLong(key);
        }
    }
    public Integer getIntegerParamByKey(String key){
        if (param == null){
            return null;
        }else {
            JSONObject jsonObject = (JSONObject) JSON.toJSON(param);
            return jsonObject.getInteger(key);
        }
    }

    public Integer getCmd() {
        return cmd;
    }

    public void setCmd(Integer cmd) {
        this.cmd = cmd;
    }

    public Object getParam() {
        return param;
    }

    public void setParam(Object param) {
        this.param = param;
    }

    public String getRequestId() {
        return requestId;
    }

    public void setRequestId(String requestId) {
        this.requestId = requestId;
    }

}
